import torch as t

x = t.randn(3,4)
y = t.randn(4,5)
z = x.mm(y)
print(z.size())
print((t.matmul(x,y) == z).all())

x = t.randn(10,3,4)
y = t.randn(10,4,5)
z = x.bmm(y)
print(z.size())
print((t.matmul(x,y) == z).all())

x = t.randn(3,4,5)
y = t.randn(5)
z = x.matmul(y)
print(z.size())

x = t.randn(3,3)
y = x.inverse()
print(x.mm(y))



print('运算')
c1 = a1 + b2 #c1 = t.add(a1,b2)
c2 = a1.clone()
c2.add_(b2) #c2 += b2
print(c2)
print(c2.t()) #只针对2D tensor转置
a = t.randn(7,)
b = t.randn(7,8)
print(t.matmul(a,b).shape) #(8)
a = t.randn(7,8)
b = t.randn(8,)
print(t.matmul(a,b).shape) #(7)
a = t.randn(3,4,5,6)
b = t.randn(1,4,6,7)
print(t.matmul(a,b).shape) #(3,4,5,7), a的最后2个维度跟b的最后2个维度能按矩阵乘法运算，前面的维度能广播
print(t.norm(b2,2,0)) #计算0维上的2范数